#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class obj_func
{
private:
    int &count;

public:
    obj_func(int &count_) : count(count_) {}

    void operator()(int val)
    {
        if (!(val & 1)) // val % 2 == 0
        {
            ++count;
        }
    }
};

int main(int argc, char const *argv[])
{
    std::vector<int> v1 = {1, 2, 3, 4, 5, 6, 7, 8};
    int even_count = 0;
    for_each(v1.begin(), v1.end(), obj_func(even_count));
    std::cout << "The number of even is " << even_count << std::endl;

    int even_count1 = 0;
    for_each(
        v1.begin(), v1.end(),
        [&even_count1](int val)
        {
            if (!(val & 1))
            {
                ++even_count1;
            }
        });
    return 0;
}
